/*
 * =====================================================================================
 *
 *       Filename:  main.cpp
 *
 *    Description:  bootstrapper for mcu.
 *
 *        Version:  1.0
 *        Created:  03/12/2015 04:04:55 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Dellinger.Zhang (mn), rainxy2000@hotmail.com
 *        Company:  TD studio
 *
 * =====================================================================================
 */

#include <iostream>

#include "mcuserver.h"

using namespace std;

int main(int argc, char** argv) 
{
	cout << "MCU server starting..." << endl;
	Zebra::config = new ctXML();
	if (NULL == Zebra::config 
			|| false == Zebra::config->init("./config.xml", "MCUSERVER")) 
	{
		std::cout << "Start failed, can't find config.xml!" << std::endl;
	}

	Zebra::global["roomsuperip"] = Zebra::config->getElementPropStr("roomsuperaddr", "ip");
	Zebra::global["roomsuperport"] = Zebra::config->getElementPropStr("roomsuperaddr", "port");
	Zebra::global["logpath"] = Zebra::config->getElementContextStr("logpath");
	Zebra::global["ifname"]	= Zebra::config->getElementContextStr("ifname");
	if ("" == Zebra::global["roomsuperip"]) {
		Zebra::global["roomsuperip"] = "192.168.12.74";
	}
	if ("" == Zebra::global["roomsuperport"]) {
		Zebra::global["roomsuperport"] = "8888";
	}
	if ("" == Zebra::global["logpath"]) {
		Zebra::global["logpath"] = "/log";
	}
	if ("" == Zebra::global["ifname"]) {
		Zebra::global["ifname"] = "eth0";
	}
	Zebra::global["logfile"] = Zebra::global["logpath"] + "/ct_mcuserver.log";

	Zebra::logger = new ctLOG();
    if (NULL == Zebra::logger 
			|| false == Zebra::logger->init(Zebra::global["logfile"], "MCUSERVER")) 
	{   
		cout << "Start failed, can't create log!" << endl;
		return 1;
	} 
	
	theserver.main();
	cout << "MCU server stopped!" << endl;
	MCUServer::delSingleton();
	return EXIT_SUCCESS;
}
